package com.xyy.saas.payment.adpater.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xyy.saas.payment.adpater.PaymentAdapter;
import com.xyy.saas.payment.adpater.chinabank.constants.ChinaBankContants;
import com.xyy.saas.payment.adpater.chinabank.service.ChinaBankAdapterService;
import com.xyy.saas.payment.adpater.config.BankConfigManager;
import com.xyy.saas.payment.common.exception.PaymentException;
import com.xyy.saas.payment.cores.bo.*;
import com.xyy.saas.payment.cores.enums.ResultCodeEnum;
import com.xyy.saas.payment.cores.enums.TransactionStatusEnum;
import com.xyy.saas.payment.cores.enums.TransactionTypeEnum;
import com.xyy.saas.payment.cores.param.TransactionParam;
import com.xyy.saas.payment.dao.model.PrePayOrder;
import com.xyy.saas.payment.dao.model.RefundOrder;
import com.xyy.saas.payment.payment.core.bo.RefundBO;
import com.xyy.saas.payment.payment.core.dto.OrderClosedDto;
import com.xyy.saas.payment.payment.core.dto.PayDto;
import com.xyy.saas.payment.payment.core.dto.PrepayDto;
import com.xyy.saas.payment.payment.core.dto.RefundDto;
import com.xyy.saas.payment.payment.core.service.PrePayOrderService;
import com.xyy.saas.payment.service.PayAccountService;
import com.xyy.saas.payment.util.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

/**
 * @author wangtianqi
 * @date 2020/7/6 10:00
 */
@Slf4j
@Service
public class ChinaBankAdapter implements PaymentAdapter {


    @Value("${chinaBank.url}")
    private String requestURL;

    @Value("${chinaBank.callBack.pay}")
    private String callBackPayUrl;

    @Value("${chinaBank.callBack.refund}")
    private String callBackRefundUrl;

    @Autowired
    private LeafUtil leafUtil;

    @Autowired
    private BankConfigManager bankConfigManager;

    @Autowired
    private PrePayOrderService prePayOrderService;

    @Autowired
    private PayAccountService payAccountService;

    static Map<String, String> map = new HashMap<>();

    static {
        map.put("alipay_mini", ChinaBankContants.CHANNEL_ALI_NAME);
        map.put("wx_mini",ChinaBankContants.CHANNEL_WX_NAME);
    }

    @Override
    public PrepayBo prepay(PrepayDto prepayDto) throws PaymentException {
        return prePayOrderService.prepayOrderByPrepayDto(prepayDto);
    }

    @Override
    public RefundBO refund(RefundDto refundDto) throws PaymentException {
        Map<String, Object> params = new HashMap<>(16);
        RefundBO refundBO = new RefundBO();
        try {
            //requestNo 请求流水号 M 商户请求流水号 ANx..32
            params.put("requestNo",leafUtil.getSnowflakeId() );
            //version 版本号 M 接口 V1.0 AN..6
            params.put("version","V1.0");
            //accessNo 接入机构号 M 该机构号由平台ᨀ供 AN..20  和商户号一起
            params.put("accessNo",bankConfigManager.getChinaBankAccessNo(refundDto.getBusinessOrderType()));
            //transId 交易类型 M 102–退货 N..6
            params.put("transId","102");
            //mchNo 商户号 M 商户号 AS..30
            params.put("mchNo",bankConfigManager.getChinaBankMch(refundDto.getBusinessOrderType()));
            //transDate 订单日期 M 商户交易订单日期 yyyyMMdd N8
            params.put("transDate",DateUtil.format(refundDto.getTransDate(),DateUtil.DATEFORMATDAY_02));
            //outTransNo 商户订单号 M 商户交易订单号 AS..32
            params.put("outTransNo",refundDto.getRefundNo());
            //oriTransDate 原订单日期 M 原交易订单日期 yyyyMMdd N8
            params.put("oriTransDate",DateUtil.format(refundDto.getOriTransDate(),DateUtil.DATEFORMATDAY_02));
            //oriOutTransNo 原商户订单号 M 原商户交易订单号 AS..32
            params.put("oriOutTransNo",refundDto.getPayNo());
            //transAmount 交易金额 M 申请退货金额，单位为分 N1
            params.put("transAmount",refundDto.getAmount());
            //refundReason 退货原因 M 退货原因 AS..256
            params.put("refundReason",refundDto.getBusinessRefundNo());
            //notifyUrl 异步通知地址 M 异步通知地址 AS..256
            params.put("notifyUrl",callBackRefundUrl);
            TreeMap<String, Object> resultTreeMap = sendToChannel(params, requestURL);
            if(resultTreeMap==null){
                log.error("ChinaBankAdapter#refund create refund failed refundDto:{}", JSON.toJSONString(refundDto));
                throw new PaymentException(ResultCodeEnum.CHANNEL_CONNECT_ERROR);
            }
            //网关应答码判断
            String returnCode = String.valueOf(resultTreeMap.get("returnCode"));
            if (StringUtils.isNotEmpty(returnCode)&&!ChinaBankContants.SUCCESS.equals(returnCode)) {
                String returnMsg = String.valueOf(resultTreeMap.get("returnMsg"));
                throw new PaymentException(ResultCodeEnum.CHANNEL_CONNECT_ERROR.getCode(),returnMsg);
            }
            //业务应答码判断
            String resultCode = String.valueOf(resultTreeMap.get("resultCode"));
            if (StringUtils.isNotEmpty(resultCode)&&
                    !ChinaBankContants.SUCCESS.equals(resultCode)&&
                    !ChinaBankContants.INSUFFICIENT_AMOUNT.equals(resultCode)&&
                    !ChinaBankContants.ORDER_PROCESSING.equals(resultCode)) {
                String resultMsg = String.valueOf(resultTreeMap.get("resultMsg"));
                throw new PaymentException(ResultCodeEnum.CHANNEL_CONNECT_ERROR.getCode(),resultMsg);
            }
            refundBO.setChannelRefundNo(String.valueOf(resultTreeMap.get("tradeNo")));
            refundBO.setChannelTransactionNo(String.valueOf(resultTreeMap.get("bankTradeNo")));
            refundBO.setRefundNo(refundDto.getRefundNo());
            refundBO.setStatus(RefundOrder.STATUS_IN);
        } catch (PaymentException e){
            log.error("ChinaBankAdapter#refund create refund error refundDto:{} ", JSON.toJSONString(refundDto), e);
            throw new PaymentException(e.getErrCode(),e.getErrMsg());
        } catch (Exception e) {
            log.error("ChinaBankAdapter#refund create refund error refundDto:{} ", JSON.toJSONString(refundDto), e);
            throw new PaymentException(ResultCodeEnum.CHANNEL_CONNECT_ERROR);
        }
        return refundBO;
    }

    @Override
    public TransactionResultBO queryTransaction(TransactionParam param) throws PaymentException {
        if(TransactionTypeEnum.PAY.getCode().equals(param.getTransactionType())) {
            return queryPay(param);
        }else if(TransactionTypeEnum.REFUND.getCode().equals(param.getTransactionType())) {
            throw new PaymentException(ResultCodeEnum.UN_SUPPORT_METHOD);
        }else{
            throw new PaymentException(ResultCodeEnum.UN_SUPPORT_METHOD);
        }
    }

    private TransactionResultBO queryPay(TransactionParam param) throws PaymentException {
        Map<String, Object> params = new HashMap<>();
        TransactionResultBO bo = new TransactionResultBO();
        bo.setTradeNo(param.getTradeNo());
        try {
            //requestNo 请求流水号 M 商户请求流水号 ANx..32
            params.put("requestNo",leafUtil.getSnowflakeId());
            //version 版本号 M 接口 V1.0 AN..6
            params.put("version","V1.0");
            //accessNo 接入机构号 M 该机构号由平台ᨀ供 AN..20  和商户号一起
            params.put("accessNo",bankConfigManager.getChinaBankAccessNo(param.getBusinessOrderType()));
            //transId 交易类型 M 101-订单查询 N..6
            params.put("transId","101");
            //mchNo 商户号 M 商户号 AS..30
            params.put("mchNo",bankConfigManager.getChinaBankMch(param.getBusinessOrderType()));
//            //transDate 订单日期 M 商户交易订单日期 yyyyMMdd N8
            PrePayOrder prePayOrder = prePayOrderService.getPrePayOrderByPayNo(param.getTradeNo());
            params.put("oriTransDate", DateUtil.format(prePayOrder.getCreateTime(), DateUtil.DATEFORMATDAY_02));
            //outTransNo 商户订单号 M 商户交易订单号 AS..32
            params.put("outTransNo", param.getTradeNo());
            TreeMap<String, Object> resultTreeMap = sendToChannel(params, requestURL);
            if(resultTreeMap==null){
                log.error("ChinaBankAdapter#queryPayStatus failed ");
                throw new PaymentException(ResultCodeEnum.CHANNEL_CONNECT_ERROR);
            }
            if(resultTreeMap.get("orderState") != null && "PAIED".equals(resultTreeMap.get("orderState"))) {
                bo.setStatus(TransactionStatusEnum.SUCCESS.getCode());
                bo.setSuccessTime(DateUtil.parase((String) resultTreeMap.get("payTime"), DateUtil.DATEFORMATDAY_02).getTime());
                bo.setChannelChargeNo((String) resultTreeMap.get("bankTradeNo"));
            }else {
                bo.setStatus(TransactionStatusEnum.TRANSACTING.getCode());
            }
            return bo;
        } catch (Exception e) {
            log.error("ChinaBankAdapter#queryPayStatus error.", e);
            throw new PaymentException(ResultCodeEnum.CHANNEL_CONNECT_ERROR);
        }
    }

    @Override
    public QueryResultBo queryPayStatus(String tradeNo, PrePayOrder prePayOrder) throws PaymentException {
        Map<String, Object> params = new HashMap<>();
        QueryResultBo bo = new QueryResultBo();
        try {
            //requestNo 请求流水号 M 商户请求流水号 ANx..32
            params.put("requestNo",leafUtil.getSnowflakeId());
            //version 版本号 M 接口 V1.0 AN..6
            params.put("version","V1.0");
            //accessNo 接入机构号 M 该机构号由平台ᨀ供 AN..20  和商户号一起
            params.put("accessNo",bankConfigManager.getChinaBankAccessNo(prePayOrder.getBusinessOrderType()));
            //transId 交易类型 M 101-订单查询 N..6
            params.put("transId","101");
            //mchNo 商户号 M 商户号 AS..30
            params.put("mchNo",bankConfigManager.getChinaBankMch(prePayOrder.getBusinessOrderType()));
            //transDate 订单日期 M 商户交易订单日期 yyyyMMdd N8
            params.put("transDate", DateUtil.format(prePayOrder.getCreateTime(), DateUtil.DATEFORMATDAY_02));
            //outTransNo 商户订单号 M 商户交易订单号 AS..32
            params.put("outTransNo", prePayOrder.getPayNo());
            TreeMap<String, Object> resultTreeMap = sendToChannel(params, requestURL);
            if(resultTreeMap==null){
                log.error("ChinaBankAdapter#queryPayStatus failed tradeNo:{} prePayOrder:{}", tradeNo,JSON.toJSONString(prePayOrder));
                throw new PaymentException(ResultCodeEnum.CHANNEL_CONNECT_ERROR);
            }
            if(resultTreeMap.get("orderState") != null && "PAIED".equals(resultTreeMap.get("orderState"))) {
                bo.setStatus(QueryResultBo.STATUS_FINISHED);
                bo.setSuccessTime(DateUtil.parase((String) resultTreeMap.get("payTime"), DateUtil.DATEFORMATDAY_02).getTime());
                bo.setChannelChargeNo((String) resultTreeMap.get("bankTradeNo"));
            }else {
                bo.setStatus(QueryResultBo.STATUS_PROCESSING);
            }
            return bo;
        } catch (Exception e) {
            log.error("ChinaBankAdapter#queryPayStatus error prePayOrder:{} ", JSON.toJSONString(prePayOrder), e);
            throw new PaymentException(ResultCodeEnum.CHANNEL_CONNECT_ERROR);
        }
    }

    @Override
    public QueryResultBo queryRefundStatus(RefundOrder refundOrder) throws PaymentException {
        String businessOrderType = payAccountService.getBusinessUserIdByAccountId(refundOrder.getUserId());
        Map<String, Object> params = new HashMap<>();
        QueryResultBo bo = new QueryResultBo();
        try {
            //requestNo 请求流水号 M 商户请求流水号 ANx..32
            params.put("requestNo",leafUtil.getSnowflakeId());
            //version 版本号 M 接口 V1.0 AN..6
            params.put("version","V1.0");
            //accessNo 接入机构号 M 该机构号由平台ᨀ供 AN..20  和商户号一起
            params.put("accessNo",bankConfigManager.getChinaBankAccessNo(businessOrderType));
            //transId 交易类型 M 101-订单查询 N..6
            params.put("transId","101");
            //mchNo 商户号 M 商户号 AS..30
            params.put("mchNo",bankConfigManager.getChinaBankMch(businessOrderType));
            //transDate 订单日期 M 商户交易订单日期 yyyyMMdd N8
            params.put("oriTransDate", DateUtil.format(refundOrder.getCreateTime(), DateUtil.DATEFORMATDAY_02));
            //outTransNo 商户订单号 M 商户交易订单号 AS..32
            params.put("oriOutTransNo", refundOrder.getRefundNo());
            TreeMap<String, Object> resultTreeMap = sendToChannel(params, requestURL);

            String resultCode = resultTreeMap.get("resultCode") != null ? (String) resultTreeMap.get("resultCode") : null;
            String orderState = resultTreeMap.get("orderState") != null ? (String) resultTreeMap.get("orderState") : null;

            if("0000".equals(resultCode)) {
                if("PAIED".equals(orderState) || "FINISHED".equals(orderState)) {
                    bo.setStatus(QueryResultBo.STATUS_FINISHED);
                    bo.setSuccessTime(DateUtil.parase((String) resultTreeMap.get("payTime"), DateUtil.YYYYMMDDHHMMSS).getTime());
                    bo.setChannelChargeNo((String) resultTreeMap.get("transNo"));
                    bo.setAmount(Integer.valueOf((String) resultTreeMap.get("transAmount")));
                }
                else if("FAILED".equals(orderState)) {
                    bo.setStatus(QueryResultBo.STATUS_FAILED);
                }
                else {
                    bo.setStatus(QueryResultBo.STATUS_PROCESSING);
                }
            }
            else {
                bo.setStatus(QueryResultBo.STATUS_FAILED);
            }

            return bo;
        } catch (Exception e) {
            log.error("ChinaBankAdapter#queryRefundStatus error refundOrder:{} ", JSON.toJSONString(refundOrder), e);
            throw new PaymentException(ResultCodeEnum.CHANNEL_CONNECT_ERROR);
        }
    }

    @Override
    public OrderClosedBo orderClosed(OrderClosedDto orderClosedDto) throws PaymentException {
        Map<String, Object> params = new HashMap<>(16);
        OrderClosedBo orderClosedBo = new OrderClosedBo();
        try {
            //requestNo 请求流水号 M 商户请求流水号 ANx..32
            params.put("requestNo",leafUtil.getSnowflakeId() );
            //version 版本号 M 接口 V1.0 AN..6
            params.put("version","V1.0");
            //accessNo 接入机构号 M 该机构号由平台ᨀ供 AN..20  和商户号一起
            params.put("accessNo",bankConfigManager.getChinaBankAccessNo(orderClosedDto.getBusinessOrderType()));
            params.put("transId","104");
            //mchNo 商户号 M 商户号 AS..30
            params.put("mchNo",bankConfigManager.getChinaBankMch(orderClosedDto.getBusinessOrderType()));
            //transDate 订单日期 M 商户交易订单日期 yyyyMMdd N8
            //transDate 订单日期 M 商户交易订单日期 yyyyMMdd N8
            params.put("transDate",DateUtil.format(orderClosedDto.getTransDate(),DateUtil.DATEFORMATDAY_02));
            //oriTransDate 原订单日期 M 原交易订单日期 yyyyMMdd N8
            params.put("oriTransDate",DateUtil.format(orderClosedDto.getOriTransDate(),DateUtil.DATEFORMATDAY_02));
            //outTransNo 商户订单号 M 商户交易订单号 AS..32
            params.put("outTransNo",leafUtil.getSnowflakeId());
            //oriOutTransNo 原商户订单号 M 原商户交易订单号 AS..32
            params.put("oriOutTransNo",orderClosedDto.getPayNo());
            TreeMap<String, Object> resultTreeMap = sendToChannel(params, requestURL);
            if(resultTreeMap==null){
                log.error("ChinaBankAdapter#orderClosed create orderClosed failed orderClosedDto:{}", JSON.toJSONString(orderClosedDto));
                throw new PaymentException(ResultCodeEnum.CHANNEL_CONNECT_ERROR);
            }
            //网关应答码判断
            String returnCode = String.valueOf(resultTreeMap.get("returnCode"));
            if (StringUtils.isNotEmpty(returnCode)&&!ChinaBankContants.SUCCESS.equals(returnCode)) {
                String returnMsg = String.valueOf(resultTreeMap.get("returnMsg"));
                throw new PaymentException(ResultCodeEnum.CHANNEL_CONNECT_ERROR.getCode(),returnMsg);
            }
            String resultCode = String.valueOf(resultTreeMap.get("resultCode"));
            if (StringUtils.isNotEmpty(resultCode) && !ChinaBankContants.SUCCESS.equals(resultCode)) {
                String resultMsg = String.valueOf(resultTreeMap.get("resultMsg"));
                throw new PaymentException(ResultCodeEnum.CHANNEL_CONNECT_ERROR.getCode(),resultMsg);
            }
            orderClosedBo.setPayNo(orderClosedDto.getPayNo());
            orderClosedBo.setStatus(OrderClosedBo.SUCCESS);
        }catch (PaymentException e){
            log.warn("ChinaBankAdapter#orderClosed create orderClosed error orderClosedDto:{} ", JSON.toJSONString(orderClosedDto));
            throw new PaymentException(e.getErrCode(),e.getErrMsg());
        }catch (Exception e) {
            log.error("ChinaBankAdapter#orderClosed create orderClosed error orderClosedDto:{} ", JSON.toJSONString(orderClosedDto), e);
            throw new PaymentException(ResultCodeEnum.CHANNEL_CONNECT_ERROR);
        }
        return orderClosedBo;
    }

    @Override
    public PayBo pay(PayDto payDto) throws PaymentException {
        Map<String, Object> params = new HashMap<>();
        String channel = payDto.getChannel().split("_")[1];
        String mode = payDto.getPayMode();
        PayBo payBo = new PayBo();
        try {
            //requestNo 请求流水号 M 商户请求流水号 ANx..32
            params.put("requestNo",leafUtil.getSnowflakeId() );
            //version 版本号 M 接口 V1.0 AN..6
            params.put("version","V1.0");
            //accessNo 接入机构号 M 该机构号由平台ᨀ供 AN..20  和商户号一起
            params.put("accessNo", bankConfigManager.getChinaBankAccessNo(payDto.getBusinessOrderType()));
            //transId 交易类型 M 100–统一下单 N..6
            params.put("transId","100");
            //mchNo 商户号 M 商户号 AS..30
            params.put("mchNo", bankConfigManager.getChinaBankMch(payDto.getBusinessOrderType()));
            //transDate 订单日期 M 商户交易订单日期 yyyyMMdd N8
            params.put("transDate", DateUtil.format(payDto.getCreateTime(), DateUtil.DATEFORMATDAY_02));
            //outTransNo 商户订单号 M 商户交易订单号 AS..32
            params.put("outTransNo", payDto.getPayNo());
            //产品类型
            params.put("productId", map.get(channel+"_"+mode));
            //transAmount 交易金额 M 申请退货金额，单位为分 N1
            params.put("transAmount", payDto.getAmount());
            //notifyUrl 异步通知地址 M 异步通知地址 AS..256
            params.put("notifyUrl",callBackPayUrl);
            ChinaBankAdapterService.getInstance().invoker(channel+mode, payDto.getMap(), params);
            TreeMap<String, Object> resultTreeMap = sendToChannel(params, requestURL);
            if(resultTreeMap==null){
                log.error("ChinaBankAdapter#pay4ChinaBank create pay failed payDto:{}", JSON.toJSONString(payDto));
                throw new PaymentException(ResultCodeEnum.CHANNEL_CONNECT_ERROR);
            }
            //网关应答码判断
            String returnCode = String.valueOf(resultTreeMap.get("returnCode"));
            if (StringUtils.isNotEmpty(returnCode)&&!ChinaBankContants.SUCCESS.equals(returnCode)) {
                String returnMsg = String.valueOf(resultTreeMap.get("returnMsg"));
                throw new PaymentException(ResultCodeEnum.CHANNEL_CONNECT_ERROR.getCode(),returnMsg);
            }
            String resultCode = String.valueOf(resultTreeMap.get("resultCode"));
            if (StringUtils.isNotEmpty(resultCode) && (!ChinaBankContants.SUCCESS.equals(resultCode) && !ChinaBankContants.ORDER_PROCESSING.equals(resultCode))) {
                String resultMsg = String.valueOf(resultTreeMap.get("resultMsg"));
                if(StringUtils.isNotEmpty(resultMsg) && resultMsg.contains(ChinaBankContants.ORDER_REPEAT)) {
                    // 订单重复没事，不算异常
                    return payBo;
                }
                throw new PaymentException(ResultCodeEnum.CHANNEL_CONNECT_ERROR.getCode(),resultMsg);
            }
            payBo.setPayNO(payDto.getPayNo());
            switch (channel) {
                case "wx" :
                    payBo.setPayLoad(WxUtil.convertWXPayLoad((String)resultTreeMap.get("payInfo")));
                    break;
                case "alipay" :
                    payBo.setPayLoad((String) resultTreeMap.get("alipayTradeNo"));
                    break;
                default:
                    break;
            }
            return payBo;
        } catch (PaymentException e) {
            log.error("ChinaBankAdapter#pay4ChinaBank create pay error payDto=" + JSON.toJSONString(payDto), e);
            throw new PaymentException(e.getErrCode(), e.getErrMsg());
        } catch (Exception e) {
            log.error("ChinaBankAdapter#pay4ChinaBank create pay error payDto=" + JSON.toJSONString(payDto), e);
            throw new PaymentException(ResultCodeEnum.CHANNEL_CONNECT_ERROR);
        }
    }

    private  TreeMap<String, Object> sendToChannel(Map<String, Object> dataMap, String requestURL) throws PaymentException {
        TreeMap<String, Object> treeMap = new TreeMap<>();
        try {
            dataMap.put("signType","RSA2");
            String signValue = SignatureUtil.getSignatureStr(dataMap);
            String privateKey = bankConfigManager.getPrivateKeyByMch(String.valueOf(dataMap.get("mchNo")));
            String signature = RSAUtil.signSHA256RSA(signValue,
                    RSAUtil.getPrivateKey(privateKey), "UTF-8");
            log.info("ChinaBankAdapter#sendToChannel 中行签名signValue:{} sign：{} 请求数据：{}",signValue, signature,dataMap);
            dataMap.put("signature", signature);
            String responseBody = HttpClientUtil.xyyHttpPostRequest(requestURL, dataMap);
            JSONObject jsonObject = JSON.parseObject(responseBody);
            for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
                String key = entry.getKey();
                String value = entry.getValue().toString();
                treeMap.put(key, value);
            }
            log.info("ChinaBankAdapter#sendToChannel 网关结果：{}, returnMsg:{}, 响应数据：{}",
                    jsonObject.getString("returnCode") , jsonObject.getString("returnMsg"),responseBody);
            if (treeMap.containsKey("signature")) {
                String mchNo = bankConfigManager.getPublicKeyByMch(String.valueOf(dataMap.get("mchNo")));
                boolean verferSignData = RSAUtil
                        .verifySHA256(SignatureUtil.getSignatureStr( treeMap), String.valueOf(treeMap.get("signature")),
                                RSAUtil.getPublicKey(mchNo),"UTF-8");
                log.info("ChinaBankAdapter#sendToChannel 返回报文签名数据：{}, 响应验签:{}",SignatureUtil.getSignatureStr(treeMap),verferSignData);
                if (!verferSignData) {
                    throw new PaymentException(ResultCodeEnum.CHANNEL_CONNECT_ERROR);
                }
            }
        } catch (Exception e) {
            log.error("ChinaBankAdapter#sendToChannel send msg error dataMap:{} requestURL:{}", JSON.toJSONString(dataMap), requestURL, e);
            throw new PaymentException(ResultCodeEnum.CHANNEL_CONNECT_ERROR);
        }
        return treeMap;
    }


}
